﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Modelo;
using System.IO;

namespace Interfaz
{
    /// <summary>
    /// Interaction logic for InicioAdmin.xaml
    /// </summary>
    public partial class InicioAdmin : Window
    {
        Usuario usuario;
        public InicioAdmin(Usuario usuario)
        {
            InitializeComponent();
            frame1.Source = new Uri("VentanaInicioCuenta.xaml",UriKind.Relative);
            this.usuario = usuario;
            cargarDatos();
        }
        private BitmapImage GetBitmapImageFromBytes(byte[] bytes)
        {  
           using (MemoryStream ms = new MemoryStream(bytes))
           {
              BitmapImage btm = new BitmapImage();
              btm.BeginInit();
              btm.StreamSource = ms;
              btm.CacheOption = BitmapCacheOption.OnLoad;
              btm.EndInit();
              return btm;
           }
        }

        private void cargarDatos()
        {
            labelApellido.Content = usuario.Apellido;
            labelEmail.Content = usuario.Email;
            labelNombre.Content = usuario.Nombre;
            labelNombreUsuario.Content = usuario.NombreUsuario;
            labelCargo.Content = usuario.Cargo;
            image1.Source = GetBitmapImageFromBytes(usuario.Imagen);
        }
        private void buttonContrasena_Click(object sender, RoutedEventArgs e)
        {
            frame1.Source = new Uri("Registrar.xaml",UriKind.Relative);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void Window_Closed(object sender, EventArgs e)
        {
            
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            frame1.Source = new Uri("CambiarContrasena.xaml", UriKind.Relative);
        }

        private void buttonLogs_Click(object sender, RoutedEventArgs e)
        {
            LOGS logs = new LOGS();
            logs.ShowDialog();
        }

        private void button6_Click(object sender, RoutedEventArgs e)
        {
            frame1.Source = new Uri("RegistrarEmpleado.xaml", UriKind.Relative);
        }

        private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            MainWindow main = new MainWindow();
            main.Show();
        }

        private void button5_Click(object sender, RoutedEventArgs e)
        {
            frame1.Source = new Uri("RegistrarProducto.xaml", UriKind.Relative);
        }
    }
}
